import { Member } from './member-model.js'
const app = getApp()
const member = new Member()

Page({
    /**
     * 页面的初始数据
     **/
    data: {
        userInfo: null,
        income: null
    },
    /*
    * 生命周期函数--监听页面加载
    */
    onLoad: function (options) {
        
        let that = this;
        //判断用户是否登录
        let userInfo = app.globalData.userInfo;
        if (userInfo) {
        this.setData({
            userInfo: userInfo,
        })
        } else {
        wx.getUserInfo({
            success: function (res) {
            that.setData({
                userInfo: res.userInfo
            })
            }
        })
        }
    },
    goIndex(){
        wx.switchTab({
        url: '/pages/index/index'
        })
    },
    onPromotion(){
        wx.navigateTo({
        url: '/pages/role/myPromotion/myPromotion'
        })
    },
    onShow(){
        member.getIncome({}, res => {
            wx.stopPullDownRefresh(); //停止下拉刷新
            if (res.status) {
                this.setData({
                    income: res.data
                })
                console.log('推广佣金', res.data)
            } else {
                wx.showToast({
                    title: res.message,
                    icon: 'none'
                })
            }
        })
    },
    onPullDownRefresh(){
        this.onShow()
    },
    onShareAppMessage: function () {
        app.aldstat.sendEvent('会员中心-分享');

        wx.showShareMenu({
            withShareTicket: true
        });

        let phone = wx.getStorageSync('phone');
        let inviteDaigoCode = wx.getStorageSync('inviteDaigoCode')
        let ownInviteCode = wx.getStorageSync('ownInviteCode')
        let userStatus = wx.getStorageSync('userStatus')
        let nowInviteCode = userStatus > 1 ? ownInviteCode : inviteDaigoCode        
        console.log("分享的phone================", phone)
        return {
            title: "一线品牌一折起", //storeInfo.brandName,
            path: `/pages/index/index?invitePhone=${phone}`,
            imageUrl: "https://goods.dingdian.xin/Fp3ptFYZ54XLi2L2OuAMjP_D45hJ?imageMogr2/thumbnail/400000@",
            success: res => {
                if (res.shareTickets) {
                    console.log(res.shareTickets);
                    wx.getShareInfo({
                        shareTicket: res.shareTickets[0],
                        success: d => {
                            console.log(d);
                        }
                    })
                }
            }
        }
    },
})